package it.isa.demo.controller;

import it.isa.demo.entity.User;
import it.isa.demo.mapper.one.UserMapperOne;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author Corgile
 * @date 2022-02-28
 */
@RestController
@RequestMapping(value = "session")
public class SharedSession {
	@Value("${server.port}")
	private String port;

	@Autowired
	private UserMapperOne mapperOne;

	@GetMapping(value = "set")
	@ResponseBody
	public List<User> set(HttpSession session) {
		List<User> users = this.mapperOne.getAllUsers();
		System.out.println(users);
		session.setAttribute("users", users);
		return users;
	}

	@GetMapping(value = "get")
	@ResponseBody
	public Object get(HttpSession session) {
		return session.getAttribute("users").toString();
	}
}
